#encoding: utf-8
import re
# file = open("处理好的诗词.txt", "r",encoding='utf-8') # 以只读模式读取文件
file = open("王维.txt", "r",encoding='utf-8')
lines = []
for i in file:
	lines.append(i) #逐行将文本存入列表lines中

	new = []
for line in lines: # 逐行遍历,去掉解释等
	####### 获取符合条件的全部诗词#####
	# if line.find('\'dynasties\': \'〔唐代〕\'')<0  and line.find('\'dynasties\': \'〔宋代〕\'')<0:  # 将唐代诗歌全部输出
	# # if line.find('\'authors\': \'王维\'')>1:  #将唐代诗歌全部输出
	# 	print(line+'\n')
	# 	print('================')
	#
	# 	new.append(line)
	# else:
	# 	continue


	######获取诗词内容#########
	contents =re.findall(r' \'contents\': \'(.*?)\'',line,re.DOTALL)
	for content in contents:
		str = "".join(content)
		print(content)
		new.append(str)
# 以写的方式打开文件，如果文件不存在，就会自动创建，如果存在就会覆盖原文件
#
file_write = open("王维内容.txt", "w",encoding='utf-8')
for var in new:
	file_write.writelines(var)
	file_write.writelines('\n')#得到全部的就屏蔽掉这一句，不然会空一行
file_write.close()